Delete object with descendants

I try to delete/perge objects with descendants and have the following error

 

:-R-E- DXL: <Line:49> cannot delete Object: object has descendants

How to delete object with leafs?

 

I see that ambiguous  statement:

Note: You cannot delete or purge objects that have descendants if sorting is turned on. 
Leaf objects can be deleted when sorting is on. 

But does not work.

 


Dinio - Wed Jan 13 10:35:14 EST 2016

Re: Delete object with descendants
Mathias Mamsch - Thu Jan 14 04:04:57 EST 2016

This has been discussed on the forum. There should be at least one example code, that will recursively delete the objects and try to remove links on the objects first. Regards, Mathias

Re: Delete object with descendants
Dinio - Thu Jan 14 04:16:01 EST 2016

Mathias Mamsch - Thu Jan 14 04:04:57 EST 2016

This has been discussed on the forum. There should be at least one example code, that will recursively delete the objects and try to remove links on the objects first. Regards, Mathias

yes, I saw sorry:

1. Delete out coming links

2. Delete in coming links

3. Check if is leaf is yes - delete

4. If is not leaf go to 1

Re: Delete object with descendants
Dinio - Fri Jan 15 05:18:47 EST 2016

Hi I created a script but have very strange behavior not all objects are processed WHy is recursion correct? I do not have rows,tables or softdelete objects. Just some of the objects are deleted not all? Or is it good idea to pass the same Module object in recursion? I do not post the part with the link because this without in/out links deletion is still not working. To say that our root object do not have any in/out links.

void deleteObject(Module mod, int id, bool isSoftDeletion) {

    if (null id) error "The specified id null"
    if (null mod) error "The specified module is null"
      
    filtering off
    
    Object o2BDeleted = null
    Object o
    for o in mod do {
        int currentId = o."Absolute Number"
        if currentId == id then {
          o2BDeleted = o
          break
        }
    } 
   
    if (null o2BDeleted){
       error "No Object for deletion is found."
    }
   
    if (isSoftDeletion && isDeleted(o2BDeleted)) {
       error "The object is already deleted."
    }
   
    if (!canDelete(o2BDeleted)) {
       error "The object can not be deleted!!!"
    }
    
    Object childObj = null
    for childObj in all o2BDeleted do {
        int absNumber = childObj."Absolute Number"
        deleteObject (mod, absNumber, isSoftDeletion)
    }
   
    
    if (cell o2BDeleted || row o2BDeleted || isDeleted o2BDeleted) {
            print "nothing"
    } else {
        int absNumber = o2BDeleted."Absolute Number"
        
        if (isSoftDeletion) {
        
            softDelete(o2BDeleted)
           } elseif (isDeleted(o2BDeleted)) {
           
            purgeObject_ (o2BDeleted)
        } else {
        
            hardDelete(o2BDeleted) 
        }
    }
    flushDeletions()
}

And we call the function:

 

   noError()
    Module mod = edit(/root/project)
    deleteObject(mod, id, false)
    close(mod)

Re: Delete object with descendants
Dinio - Mon Jan 18 03:00:37 EST 2016

Where can be the problem is there other function like  flushDeletions() ? Which I do not use properlly?